local skel = fk.CreateSkill {
  name = "emo__jiefen_other&",
}

skel:addEffect("active", {
  prompt = "#emo__jiefen-active",
  card_num = 1,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  target_num = 1,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return #selected_cards == 1 and #selected == 0 and to_select:hasSkill("emo__jiefen")
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function (self, room, effect)
    local player, to = effect.from, effect.tos[1]
    local mainName = "emo__jiefen"
    player:broadcastSkillInvoke(mainName)
    local cards = table.simpleClone(effect.cards)
    if to.dead then return end
    room:addTableMarkIfNeed(to, "emo__jiefen_tar", player.id)
    if #cards == 0 and not player:isNude() then
      cards = room:askToCards(player, {
        min_num = 1, max_num = 1, include_equip = true, cancelable = false, skill_name = mainName,
        prompt = "#emo__jiefen-give"
      })
    end
    room:obtainCard(to, cards, false, fk.ReasonGive, player, mainName)
    if player.dead or to.dead then return end
    room:changeMaxHp(to, -1)
    room:changeMaxHp(player, 1)
    if not to.dead and not player.dead and not player:isKongcheng() then
      local hand = player:getCardIds("h")
      local use = room:askToUseRealCard(to, {
        pattern = hand, expand_pile = hand, skill_name = mainName, prompt = "#emo__jiefen-use"
      })
      if not use then
        room:changeMaxHp(to, -1)
        if not to.dead then
          room:recover { num = 1, skillName = mainName, who = to, recoverBy = to }
        end
      end
    end
  end,
})


Fk:loadTranslationTable{
  ["emo__jiefen_other&"] = "结芬",
  [":emo__jiefen_other&"] = "出牌阶段限一次，你可以将一张牌交给柴郡，并获得其一点体力上限，然后其观看你手牌并使用其中一张，若未使用，其减少一点体力上限并恢复一点体力。",

  ["#emo__jiefen-active"] = "结芬：你可以将一张牌交给柴郡，并获得其一点体力上限",
  ["#emo__jiefen-give"] = "结芬：你须将一张牌交给柴郡",
  ["#emo__jiefen-use"] = "结芬：你可以使用其一张手牌",
}

return skel
